<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .parent{
            width:200px;
            height: 200px;
            border:1px solid #333;
            position: relative;
        }
        .parent>div{
            width:100%;
            height: 100%;
            position: absolute;
        }
        .html{
            background-color: red;
            z-index: 100;
        }

        .css{
            background-color: yellow;
        }
        .current{
            color:orange;
        }
        li{
            cursor: pointer;
        }
    </style>
</head>
<body>
    <ul>
        <li class="current">html</li>
        <li>css</li>
    </ul>
    <div class="parent">
        <div class="html">
            html
        </div>
        <div class="css">
            css
        </div>
    </div>
    <script>
        var lis = document.getElementsByTagName("li");
        var divs = document.querySelectorAll(".parent div");
        
        for(let i=0;i<lis.length;i++){
            // 添加自定义属性
            lis[i].index = i;
            lis[i].onclick  =  function(){
                /* 1.遍历让所有的li移除class="current" */
                for(let i=0;i<lis.length;i++){
                    lis[i].classList.remove("current");
                }
                /* 2.让当前元素添加class="current" */
                this.classList.add("current")
                console.log(this.index)


                /* 3.让所有的div隐藏 */
                for(let i=0;i<divs.length;i++){
                    divs[i].style.display = "none"
                }
                /* 4.让对应的下标的div去显示 */
                divs[this.index].style.display = "block";

            }
        }

    </script>
</body>
</html>